package com.zhijian.wharf.util.pay;

import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;


@Component
public class ApiTestV2 {

	public static void main(String[] args) throws Exception{

//		testPay();//统一下单，异步类交易
//		testScanPay();//统一扫码，被扫交易
//		testCancel();//撤销
		testRefund();//退款
//		testQuery();//查询
	}

	private static String onlyOnce(String dateStr) {
		LocalDateTime time = LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
		return time.format(DateTimeFormatter.ofPattern("ss mm HH dd MM ? yyyy"));
	}


	public static void testScanPay() throws Exception {
		// TODO Auto-generated method stub
		SybPayService service = new SybPayService();
		String reqsn = String.valueOf(System.currentTimeMillis());
		Map<String, String> map = service.scanPay(1, reqsn,  "", "备注",  "134775931316089668","","","","");
		print(map);
	}

	public static void testQuery() throws Exception{
		SybPayService service = new SybPayService();
		String response = service.query("", "221026110544053934");
		System.out.println(response);
	}
	
	public static void testRefund() throws Exception{
		SybPayService service = new SybPayService();
		String reqsn = String.valueOf(System.currentTimeMillis());
		String response = service.refund("1", reqsn, "", "IO782788791651020800");
		System.out.println(response);
	}
	
	public static void testCancel() throws Exception{
		SybPayService service = new SybPayService();
		String reqsn = String.valueOf(System.currentTimeMillis());
		Map<String, String> map = service.cancel(1, reqsn, "112094120001088316", "");
		print(map);
	}
	
	public static void testPay() throws Exception{
		SybPayService service = new SybPayService();
		String reqsn = String.valueOf(System.currentTimeMillis());

		String response = service.pay("100", reqsn, "W06", "", "", "ogeSj5T4tqkuclhGZ_AdaVZCEy_U", "","","","","","", "", "", "", "", "", "", "","");
		System.out.println(response);
	}
	
	public static void print(Map<String, String> map){
		System.out.println("返回数据如下:");
		if(map!=null){
			for(String key:map.keySet()){
				System.out.println(key+";"+map.get(key));
			}
		}
	}
	
	
}
